package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JdbcDemo4 {
    public static void main(String[] args) {

        try(
                Connection connection=DBUtil.getConnection()
        ) {
            Statement statement=connection.createStatement();//创建语句执行对象
            String sql="SELECT id,name,salary,title FROM teacher";
            ResultSet resultset = statement.executeQuery(sql);
            while(resultset.next())
            {
                int id=resultset.getInt("id");
                String name=resultset.getString("name");
                int salary=resultset.getInt("salary");
                String title=resultset.getString("title");
                System.out.println(id+"    "+name+"   "+salary+"   "+title);
            }
        } catch (SQLException e) {
           e.printStackTrace();
        }
    }
}
